(defvar shared-lisp-dir (expand-file-name "~/.emacs.d/lib")
  "Directory containing Emacs libraries required for personal setup.")
(defvar personal-lisp-dir (expand-file-name "~/.emacs.d")
  "Directory containing personal Emacs preference files.")

(add-to-list 'load-path shared-lisp-dir)
(add-to-list 'load-path personal-lisp-dir)

(defun load-configs (lib-name)
  "Call `load' on a given set of filenames.

First, attempt to load LIB-NAME.

Then attempt to load the file name consisting of LIB-NAME, followed by a
hyphen, followed by a suffix based on `system-type'; sequences of non-
alphanumeric characters in the suffix are replaced with hyphens. Attempt
to load the resulting filename.

Then attempt to load the file name consisting of LIB-NAME, a hyphen, and
a suffix based on the value of the built-in variable `system-name' with
similar substitution of non-alphanumeric character sequences.

Any or all of these files may be missing without raising errors.

Example: on a system named 'foo.example.com' running an operating system
known to Emacs as 'bar/bazix', (load-configs \"xyz\") will attempt to load
the files 'xyz', 'xyz-bar-bazix', and 'xyz-foo-example-com'."
  (setq unsafe-regexp "[^A-Za-z0-9]+")
  (load lib-name t)
  (load (concat lib-name "-"
		(replace-regexp-in-string
                 unsafe-regexp "-"
                 (symbol-name system-type))) t)
  (load (concat lib-name "-"
		(replace-regexp-in-string
                 unsafe-regexp "-" system-name)) t))

(load-configs "personal-common")
(if window-system
    (load-configs "personal-gui")
  (load-configs "personal-terminal"))
